package com.aiju.cash.core.api;

import com.aiju.app.callback.HttpCallback;
import com.aiju.common.http.interceptor.HttpFactory;
import com.aiju.widgit.dialog.DialogHelper;

import java.util.HashMap;
import java.util.Map;

import static com.aiju.app.config.ConfigManager.INIT_SERVER_HOST;

/**
 * @author: 佐为
 * @date: 2017-03-27 10:14
 * @version: V1.0
 * @Description: 账本
 */
public class AccountApi extends BaseApi {

    private String accountList = INIT_SERVER_HOST + "/account/list";
    private String accountSave = INIT_SERVER_HOST + "/account/save";
    private String accountDelete = INIT_SERVER_HOST + "/account/delete";
    private String accountDefault = INIT_SERVER_HOST + "/account/setDefault";
    private String accountUpdate = INIT_SERVER_HOST + "/account/update";
    private String accountUserList = INIT_SERVER_HOST + "/account/accountUserList";
    private String accountShare = INIT_SERVER_HOST + "/account/share";
    private String accountUnShare = INIT_SERVER_HOST + "/account/unShare";
    private String setBudget = INIT_SERVER_HOST + "/account/setBudget";
    private String get = INIT_SERVER_HOST + "/account/getBudget";

    private String itemList = INIT_SERVER_HOST + "/item/list";
    private String itemSave = INIT_SERVER_HOST + "/item/save";
    private String itemUpdate = INIT_SERVER_HOST + "/item/update";
    private String itemDelete = INIT_SERVER_HOST + "/item/delete";
    private String itemGet = INIT_SERVER_HOST + "/item/get";
    private String listByDate = INIT_SERVER_HOST + "/item/listByDate";

    private HttpFactory instance;

    public AccountApi(DialogHelper dialogHelper) {
        super(dialogHelper);
        instance = HttpFactory.getInstance();
        instance.setDialogHelper(dialogHelper);
    }

    public void setDialogHelper(DialogHelper dialogHelper) {
        instance.setDialogHelper(dialogHelper);
    }

    /**
     * 账本列表
     *
     * @param currentNum
     * @param pageSize
     * @param callback
     */
    public void accountList(int currentNum, int pageSize, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("storeId", mUser.getStoreId());
        map.put("operatorId", mUser.getOperatorId());
        map.put("currentNum", String.valueOf(currentNum));
        map.put("pageSize", String.valueOf(pageSize));
        map.put("token", mUser.getToken());
        instance.makeProxy().requestPost(accountList, map, callback);
    }

    /**
     * 账本添加
     *
     * @param name
     * @param color
     * @param callback
     */
    public void accountAdd(String name, int color, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("name", name);
        map.put("storeId", mUser.getStoreId());
        map.put("color", String.valueOf(color));
        map.put("token", mUser.getToken());
        instance.makeProxy().requestPost(accountSave, map, callback);
    }

    /**
     * 设置默认账本接口
     *
     * @param id
     * @param callback
     */
    public void accountSetDefault(String id, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("id", id);
        map.put("storeId", mUser.getStoreId());
        map.put("token", mUser.getToken());
        instance.makeProxy().requestPost(accountDefault, map, callback);
    }

    /**
     * 账本删除
     *
     * @param id
     * @param callback
     */
    public void accountDelet(String id, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("id", id);
        map.put("token", mUser.getToken());
        instance.makeProxy().requestPost(accountDelete, map, callback);
    }

    /**
     * 账本更新
     *
     * @param id
     * @param name
     * @param isDefault
     * @param status
     * @param color
     * @param callback
     */
    public void accountUpdate(String id, String name, String isDefault, String status, int color, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("id", id);
        map.put("name", name);
        map.put("isDefault", isDefault);
        map.put("status", status);
        map.put("color", String.valueOf(color));
        map.put("token", mUser.getToken());
        instance.makeProxy().requestPost(accountUpdate, map, callback);
    }

    /**
     * 账本分享/取消分享
     *
     * @param id
     * @param callback
     */
    public void setAccountShare(String id, String operatorId, boolean share, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("id", id);
        map.put("operatorId", operatorId);
        map.put("storeId", mUser.getStoreId());
        map.put("token", mUser.getToken());
        if (share) {
            instance.makeProxy().requestPost(accountShare, map, callback);
        } else {
            instance.makeProxy().requestPost(accountUnShare, map, callback);
        }
    }

    /**
     * 账本下员工列表
     *
     * @param id
     * @param callback
     */
    public void accountUserList(String id, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("id", id);
        map.put("storeId", mUser.getStoreId());
        map.put("token", mUser.getToken());
        instance.makeProxy().requestPost(accountUserList, map, callback);
    }


    /**
     * 设置预算
     *
     * @param id
     * @param callback
     */
    public void setBudget(String id, String budgetType, String budgetMoney, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("id", id);
        map.put("budgetType", budgetType);
        map.put("budgetMoney", budgetMoney);
        map.put("token", mUser.getToken());
        instance.makeProxy().requestPost(setBudget, map, callback);
    }


    /**
     * 账本信息接口
     *
     * @param id
     * @param callback
     */
    public void get(String id, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("id", id);
        map.put("token", mUser.getToken());
        instance.makeProxy().requestPost(get, map, callback);
    }

    /**
     * 账目列表接口
     *
     * @param id
     * @param callback
     */
    public void itemList(String id, String currentNum, String pageSize, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("accountId", id);
        map.put("currentNum", currentNum);
        map.put("pageSize", pageSize);
        map.put("token", mUser.getToken());
        map.put("storeId", mUser.getStoreId());
        instance.makeProxy().requestPost(itemList, map, callback);
    }

    /**
     * 账目删除
     *
     * @param id
     * @param callback
     */
    public void itemDelete(String id, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("id", id);
        map.put("token", mUser.getToken());
        map.put("operatorId", mUser.getOperatorId());
        instance.makeProxy().requestPost(itemDelete, map, callback);
    }

    /**
     * 账目删除
     *
     * @param accountId
     * @param callback
     */
    public void listByDate(String accountId, String date, String currentNum, String pageSize, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("accountId", accountId);
        map.put("date", date);
        map.put("currentNum", currentNum);
        map.put("pageSize", pageSize);
        map.put("token", mUser.getToken());
        instance.makeProxy().requestPost(listByDate, map, callback);
    }

    /**
     * 账目添加接口
     *
     * @param callback
     */
    public void itemSave(String categoryName, String accountId, String money,
                         String type, String accountType, String createDate, String remark, String imageType, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("categoryName", categoryName);
        map.put("storeId", mUser.getStoreId());
        map.put("accountId", accountId);
        map.put("money", money);
        map.put("type", type);
        map.put("accountType", accountType);
        map.put("operatorName", mUser.getUserName());
        map.put("operatorId", mUser.getOperatorId());
        map.put("createDate", createDate);
        map.put("token", mUser.getToken());
        map.put("remark", remark);
        map.put("imageType", imageType);
        instance.makeProxy().requestPost(itemSave, map, callback);
    }

    /**
     * 账目修改接口
     *
     * @param callback
     */
    public void itemUpdate(String id, String type, String categoryName, String money,
                           String accountType, String modifyDate, String remark, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("id", id);
        map.put("type", type);
        map.put("categoryName", categoryName);
        map.put("money", money);
        map.put("accountType", accountType);
        map.put("modifyDate", modifyDate);
        map.put("remark", remark);
        map.put("token", mUser.getToken());
        instance.makeProxy().requestPost(itemUpdate, map, callback);
    }

    /**
     * 账目详情
     *
     * @param callback
     */
    public void itemGet(String id, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("id", id);
        map.put("token", mUser.getToken());
        instance.makeProxy().requestPost(itemGet, map, callback);
    }
}
